package com.liquidhorse.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

import com.liquidhorse.core.TLEvent;

public class HeavyRenderer implements ListCellRenderer<TLEvent> {

	@Override
	public Component getListCellRendererComponent(JList<? extends TLEvent> list,
			final TLEvent event, int index, boolean isSelected, boolean cellHasFocus) {

		JPanel p = new JPanel();
		JLabel lbl = new JLabel();
		
		lbl.setForeground(new Color(19, 23, 62));
		
		p.add(lbl);
		lbl.setPreferredSize(new Dimension(500, 50));
		
		StringBuilder sb = new StringBuilder(event.getDescription());
		int i = 0;
		while ((i = sb.indexOf(" ", i + 60)) != -1) {
		    sb.replace(i, i + 1, "<br>");
		}
		p.setToolTipText("<html>" + sb.toString() + "</html>");
		
		lbl.setText("<html><u>" + event.getTitle() + "</u><br>" 
				+ event.getStatus()
				+ "<br>" + event.getKST() + " " + event.getCEST() + " " + event.getPDT() + " " + event.getEDT()
				+ "</html>");
		
		if (isSelected) {
			p.setBackground(new Color(179, 191, 209));
		} else {
			p.setBackground(new Color(217, 221, 224));
		}
		
		return p;
	}

}
